package com.dingup.mock.handler;

import com.dingup.mock.enums.MarkTypeEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by liuhaoyu on 16/7/8.
 */
public class MarkTypeEnumHandler extends BaseTypeHandler<MarkTypeEnum> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, MarkTypeEnum parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, parameter.getCode());
    }

    @Override
    public MarkTypeEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return MarkTypeEnum.valueOf(rs.getString(columnName).toUpperCase());
    }

    @Override
    public MarkTypeEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return MarkTypeEnum.valueOf(rs.getString(columnIndex).toUpperCase());
    }

    @Override
    public MarkTypeEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return MarkTypeEnum.valueOf(cs.getString(columnIndex).toUpperCase());
    }
}
